﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;
using System.Data.OleDb;

namespace jiemiansheji
{
    public partial class connection : Form
    {
        public static string newname="";
        public connection()
        {
            InitializeComponent(); 
        }

        private void ConnectionTest_Click(object sender, EventArgs e)
        {
           // string ConnectionString = "Data Source="+servicesid.Text+";Persist Security Info=True;User ID="+UserID.Text+";Password="+Password.Text+";";
            string ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST ="+ MainAddress.Text+")(PORT = "+Port.Text+")))(CONNECT_DATA =(SERVICE_NAME = "+servicesid.Text+")));Persist Security Info=True;User ID="+UserID.Text+";Password="+Password.Text+";";
           // OracleConnection conn = new OracleConnection("Data  Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.204)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)));User ID=viot;Password=viot;");
            bool IsCanConnectioned = false;
           OracleConnection conn = new OracleConnection(ConnectionString);
            try
            {
                conn.Open();
                IsCanConnectioned = true;
            }
            catch
            {
                IsCanConnectioned = false;
            }
            finally
            {
                conn.Close();
            }
            if (IsCanConnectioned)
            {
                MessageBox.Show("连接成功");
            }
            else
            {
                MessageBox.Show("连接不成功");
            }
        }

        private void Cancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void OK_Click(object sender, EventArgs e)
        {
            MainForm.haveadd=true;
            newname = ConnectionName.Text;
            this.Close();
        }
    }
}
